/*
 * Package: service
 * FileName: MenuListService.java
 *  
 * Created by pandian on Jan 28, 2011
 */
package service;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import dao.IMenuDAO;
import dao.IModuleDAO;
import bean.MenuItem;
import bean.Module;
import bean.UserRole;


/**
 * The Class MenuListService.
 */
public class MenuListService implements IMenuListService {
	private IModuleDAO moduleDAO;
	private IMenuDAO menuDAO;
	
	/**
	 * Sets the menu dao.
	 * 
	 * @param menuDAO the new menu dao
	 */
	public void setMenuDAO(IMenuDAO menuDAO) {
		this.menuDAO = menuDAO;
	}

	/**
	 * Sets the module dao.
	 * 
	 * @param moduleDAO the new module dao
	 */
	public void setModuleDAO(IModuleDAO moduleDAO) {
		this.moduleDAO = moduleDAO;
	}


	/* (non-Javadoc)
	 * @see service.IMenuListService#getModuleList()
	 */
	@Override
	public List<Module> getModuleList() {
		return moduleDAO.list();
	}


	@Override
	public Set<MenuItem> getMenuList(Long[] selectedMenuItem) {
		Set<MenuItem> result = new TreeSet<MenuItem>();
		if (selectedMenuItem!=null){
			for (Long l:selectedMenuItem){
				MenuItem menuItem = this.menuDAO.find(l);
				result.add(menuItem);
			}
		}
		return result;
	}

	@Override
	public Long[] getArray(UserRole newUserRole) {
		Set<MenuItem> selectedMenuItem = newUserRole.getMenuList();
		Long[] idAry = new Long[selectedMenuItem.size()];
		int c=0;
		for (MenuItem l:selectedMenuItem){
			idAry[c] = l.getId();
			c++;
		}
		return idAry;
	}

	@Override
	public List<MenuItem> getMenuList() {
		return this.menuDAO.list();
	}
}
